/*
 * @(#)CompanyServiceImpl.java 创建于 2013年3月14日 
 * 
 * Copyright (c) 2013-2014 by Drow.  
 *
 */
package com.hangxin.basic.service.impl;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hangxin.basic.dao.CompanyDao;
import com.hangxin.basic.model.Company;
import com.hangxin.basic.service.CompanyService;
import com.hangxin.commons.util.PageModel;
import com.hangxin.system.model.Syslog;
import com.hangxin.system.service.SyslogService;


@Service
public class CompanyServiceImpl implements CompanyService
{
	@Resource
	private CompanyDao companyDaoImpl;
	
	@Resource
	private SyslogService syslogServiceImpl;// 系统日志操作的Service
	/**
	 * 根据id查找组织结构
	 */
	@Override
	public Map<String, Object> companyFindById(Long id){
		Object[] params = new Object[]{id};
		return companyDaoImpl.companyFindById(params);
	}
	
	public List<Map<String, Object>> companyFind(){
		return companyDaoImpl.companyFind();
	}

	public PageModel companylist(PageModel pageModel) {
		Object[] paramscount= new Object[]{};
		Object[] params= new Object[]{(pageModel.getPageNo()-1)*pageModel.getPageSize(),pageModel.getPageSize()};
		return companyDaoImpl.companyList(pageModel, paramscount, params);
	}

	@Transactional
	public void save(Company company,Syslog syslog) {
		if(companyDaoImpl.isExist(company.getTaxno(), company.getMachineno())>0){
			companyDaoImpl.update(company);
		}else{
			companyDaoImpl.save(company);			
			syslogServiceImpl.save(syslog);// 添加操作日志
		}
	}


}
